package com.heima.article.controller.v1;

import com.heima.article.service.ArticleBehaviorService;
import com.heima.article.service.ArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleBehaviorDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
@Slf4j
@Api(tags = "app端文章相关接口")
public class ArticleHomeController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private ArticleBehaviorService articleBehaviorService;

    /**
     * 加载首页
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @ApiOperation("加载首页")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        log.info("加载首页：{}",dto);
      //  return articleService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return articleService.load2(dto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载最新
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    @ApiOperation("加载最新")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto){
        log.info("app端加载最新信息：{}",dto);
        return articleService.load(dto,ArticleConstants.LOADTYPE_LOAD_NEW);

    }

    /**
     * 加载更多
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    @ApiOperation("加载更多")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto){
        log.info("app端加载更多信息：{}",dto);
        return articleService.load(dto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载文章操作详情 数据回显
     * @return
     */
    @PostMapping("/load_article_behavior")
    @ApiOperation("回显用户操作文章详情")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleBehaviorDto dto){
        return articleBehaviorService.loadArticleBehavior(dto);
    }
}
